<?php
// 本类由系统自动生成，仅供测试用途
class NewsAction extends CommonAction{
	 
	public function index() {   
		
		$cato = new Model('news_view');
		$cato_results = $cato->field('C_id,C_name')->group('C_id')->select();
		
		$len = 10 ; 
		foreach ($cato_results as $key => $value){
			$cato_arr[$value['C_id']] = $value;
			$news_arr[$value['C_id']] = $cato->order('News_time desc')->where('C_id = '.$value['C_id'])->limit($len)->select();
		}
		
/*		foreach($cato_arr as $k=>$v){
			echo $k."<br>";
		}*/

		//dump($news_arr);
		$this->assign('news_list',$news_arr); // 模板变量赋值   
		$this->assign('cato_list',$cato_arr);
		$this->assign('cid',"");
		$this->display("News:index"); // 输出模板   
		//dump($_SERVER);
	
	 }  

	 public function more() { 
		if(empty($_GET['cid']) || empty($_GET['cname']) ){
			redirect(PHP_FILE);
			exit;
		}
	 		$cid = $_GET['cid'];
		 	$cname = $_GET['cname'];
		 	$news = d("news_view");
		 	
		 	import("ORG.Util.Page");
		 	
		 	$count = $news->where('C_id = '.$cid)->count();
		 	$p  = new Page ($count, 20 );
		 	
		 	$p->setConfig('header','篇记录');
	        $p->setConfig('prev',"<");
	        $p->setConfig('next','>');
	        $p->setConfig('first','<<');
	        $p->setConfig('last','>>');
	        
	        $list=$news->where('C_id = '.$cid)->order('News_time desc')->limit($p->firstRow.','.$p->listRows)->findAll();
	        $page = $p->show (); 
	        $this->assign ( "cid", $cid );
	        $this->assign ( "cname", $cname );
			$this->assign ( "page", $page );
	        $this->assign ( "news_list", $list );
	        $this->assign ("current_p",$p->nowPage);
	        
	        $this->display("News:index2"); 
	        
     }
	 
	 public function show() { 
		if(empty($_GET['nid'])){
			redirect(PHP_FILE);
			exit;
		}
	 	
		$news_id = $_GET['nid'];
		$news = d("news_view")->where("News_id = '".$news_id."'")->findall();
		
		//echo d("news_view")->getLastSql(); 
		
		$this->assign ( "nowp", $_GET['nowp']);
		$this->assign ("current_p",$p->nowPage);
		$this->assign ( "list", $news );
		
		//dump($list);
		$this->display("News:news_content");
	 }
}
?>